<template>
  <div>
    <!-- 导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/constanttype' }">常数类型管理</el-breadcrumb-item>
      <el-breadcrumb-item>常数项目管理</el-breadcrumb-item>
      <el-breadcrumb-item>常数项目修改</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form
      style="width: 60%"
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="id">
        <el-input v-model="ruleForm.id" readonly></el-input>
      </el-form-item>

      <el-form-item label="常数类编码" prop="constantcode">
        <el-input v-model="ruleForm.constantcode"></el-input>
      </el-form-item>

      <el-form-item label="常数类名称" prop="constantname">
        <el-input v-model="ruleForm.constantname"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        id: "",
        constantcode: "",
        constantname: "",
        delmark: "1",
      },
      rules: {
        constantcode: [
          {
            required: true,
            message: "常数类编码不能为空",
            trigger: "blur",
          },
        ],
        constantname: [
          {
            required: true,
            message: "常数类名称不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    submitForm(ruleForm) {
      const _this = this;
      this.$http
        .put("http://localhost:8085/his/constantitem/update", this.ruleForm)
        .then(function (resp) {
          console.log(resp);
          if (resp.data == "success") {
            alert("修改成功");
            _this.$router.push("/constanttype");
          }
        });
    },
  },

  created() {
    const _this = this;
    this.$http
      .get(
        "http://localhost:8085/his/constantitem/findById/" +
          this.$route.query.id
      )
      .then(function (resp) {
        _this.ruleForm = resp.data;
      });
  },
};
</script>
